﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using RealmMudLib.Screens.Base;
using RealmMudLib.Managers;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework;
using RealmMudLib.GameObjects;
using XNAGameConsole;
using Microsoft.Xna.Framework.Input;

namespace RealmMudLib.Screens
{
    public class ConnectionRefused : GameScreen
    {
        private SpriteFont Font { get; set; }
        private Vector2 Center { get; set; }
        private string Message { get; set; }
        private Button TestButton { get; set; }
        //private CommandConsoleBase Console { get; set; }
        private GameConsole Console { get; set; }
        private ParticleEngine.ParticleEngine particleEngine;

        public ConnectionRefused(string msg, ScreenManager manager)
            : base(manager)
        {
            Font = this.Manager.BaseGame.Content.Load<SpriteFont>("Fonts\\Arial");
            Message = msg;
            Center = new Vector2(this.Manager.BaseGame.GraphicsDevice.Viewport.Bounds.Width / 2 - (Message.Length * 4), this.Manager.BaseGame.GraphicsDevice.Viewport.Bounds.Height / 2);
            TestButton = new Button(new Vector2(Center.X , Center.Y + 40),
                this.Manager.BaseGame.Content.Load<Texture2D>("Buttons\\Blue\\blue_normal"),
                "Not Selected",
                this.Manager.BaseGame.Content.Load<Texture2D>("Buttons\\Blue\\blue_selected"),
                "Selected !!",
                this);
            this.AddGameObject(TestButton);

            // ParticleEngineTest
            List<Texture2D> textures = new List<Texture2D>();
            textures.Add(this.Manager.BaseGame.Content.Load<Texture2D>("Particles\\circle"));
            textures.Add(this.Manager.BaseGame.Content.Load<Texture2D>("Particles\\star"));
            textures.Add(this.Manager.BaseGame.Content.Load<Texture2D>("Particles\\diamond"));
            particleEngine = new ParticleEngine.ParticleEngine(textures, new Vector2(400, 240));


            this.Console = new GameConsole(this.Manager.BaseGame, new SpriteBatch(this.Manager.BaseGame.GraphicsDevice));
            //var commands = new IConsoleCommand[] { new MovePlayerCommand(player), new RotatePlayerDegreesCommand(player) };
            
            //this.Console.AddCommand("test",

            /*
             * this.Console = new CommandConsoleBase(this.Manager.BaseGame, Font);
            this.Console.Active = true;
            this.Console.Enabled = true;
            this.Console.Initialize();
            this.Console.Height = 200;
            this.Console.Width = 100;
            this.Manager.BaseGame.Components.Add(this.Console);
             */
        }
        public override void LoadContent()
        {
            
            base.LoadContent();
        }
        public override void Update(Microsoft.Xna.Framework.GameTime gameTime)
        {
            base.Update(gameTime);
            Center = new Vector2(this.Manager.BaseGame.GraphicsDevice.Viewport.Bounds.Width / 2 - (Message.Length*4), this.Manager.BaseGame.GraphicsDevice.Viewport.Bounds.Height / 2);
            particleEngine.EmitterLocation = new Vector2(Mouse.GetState().X, Mouse.GetState().Y);
            particleEngine.Update();
        }
        public override void Draw(Microsoft.Xna.Framework.GameTime gameTime)
        {
            spriteBatch = new SpriteBatch(this.Manager.BaseGame.GraphicsDevice);
            this.Manager.BaseGame.GraphicsDevice.Clear(Color.Red);
            this.spriteBatch.Begin();
            this.spriteBatch.DrawString(Font, Message, Center, Color.White);
            this.spriteBatch.End();
            particleEngine.Draw(spriteBatch);
            base.Draw(gameTime);
        }
        
    }
}
